package com.osexp.model;

import java.util.ArrayList;
import java.util.List;

public class pageTable implements paraConstants{	
	private List<PTE> lPtes = new ArrayList<PTE>();
	public pageTable() {
		super();
	}
	
	public void add(int iLogicalAddress,int iPhysicalAddress) {
		for(PTE pte:lPtes){
			if(pte.getiLogicalAddress()==iLogicalAddress){
				pte.setiPhysicalAddress(iPhysicalAddress);
			}
		}
		lPtes.add(new PTE(iLogicalAddress, iPhysicalAddress));
	}
	
	public void set(int iLogicalAddress,int iPhysicalAddress) {
		for(PTE pte:lPtes){
			if(pte.getiLogicalAddress()==iLogicalAddress){
				pte.setiPhysicalAddress(iPhysicalAddress);
			}
		}		
	}
	
	public void update(int iLogicalAddress,int iPhysicalAddress) {
		for(PTE pte:lPtes){
			if(pte.getiPhysicalAddress()==iPhysicalAddress){
				if(pte.getiLogicalAddress()!=iLogicalAddress){
					pte.setiPhysicalAddress(-1);
				}
			}
		}		
	}
	
	public int find(int iLogicalAddress) {
		for(PTE pte:lPtes){
			if(pte.getiLogicalAddress()==iLogicalAddress){
				return pte.getiPhysicalAddress();
			}
		}
		return -1;		
	}
	
}
